package utils

import (
	"AiBus/global"
	"AiBus/model"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

func InitSqlite() *gorm.DB {
	client := &global.App.Configuration.Database
	dsn := client.UserName + ":" + client.PassWord + "@tcp(" + client.Address + ":" + client.Port + ")/" + client.DBname +
		"?charset=utf8mb4&parseTime=True&loc=Local"
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	db.AutoMigrate(&model.User{}, &model.Grants{}, &model.Versions{}, &model.SearchUser{},
		model.Priority{}, &model.ToDoClass{}, &model.TODO{}, &model.SystemParameter{})

	return db
}
